//
//  LoginViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "LoginViewController.h"
#import <SVProgressHUD.h>

#import "LeftViewController.h"
@interface LoginViewController ()
@property (nonatomic,weak) UITextField *accountField;
@property (nonatomic,weak) UITextField *passWorldField;


@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];

  

    [self setUpView];

}


- (void)setUpView
{
    //两张图
    UIImageView *imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"product_img_logo_nor.png"]];
    imageview.frame = CGRectMake(150, 50, 65, 85);
    [self.view addSubview:imageview];
    
    UIImageView *imageviewlable = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"product_text_logo_nor.png"]];
    imageviewlable.frame = CGRectMake(150, 150, 65, 40);
    [self.view addSubview:imageviewlable];
    

    //账号
    UITextField *accountField = [[UITextField alloc]initWithFrame:CGRectMake(20, 200, 335, 40)];
    
    accountField.text = @"11";
    _accountField = accountField;
    
    //编辑后有个小叉叉
    [accountField setClearButtonMode:UITextFieldViewModeAlways];
    
    //关闭自动联想
    [accountField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //首字母
    [accountField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
    
    //占位符
    accountField.placeholder = @"请输入您的账号";
    
    //边框样式
    accountField.borderStyle = UITextBorderStyleRoundedRect;
    
    //添加
    [self.view addSubview:accountField];
    
    //密码
    UITextField *passWorldField = [[UITextField alloc]initWithFrame:CGRectMake(20, 255, 335, 40)];
    
    passWorldField.text =@"22";
    
    
    //编辑后有个小叉叉
    [passWorldField setClearButtonMode:UITextFieldViewModeAlways];
    
    //密文
    passWorldField.secureTextEntry = YES;
    
    _passWorldField = passWorldField;
    
    //占位符
    passWorldField.placeholder = @"请输入您的密码";
    
    //边框样式
    passWorldField.borderStyle = UITextBorderStyleRoundedRect;
    
    [self.view addSubview:passWorldField];
    
    //登陆btn
    UIButton *logBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 320, 335, 50)];
    
    [logBtn addTarget:self action:@selector(loginclick) forControlEvents:UIControlEventTouchUpInside];
    
    [logBtn setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
    
    [logBtn setTitle:@"Log in" forState:UIControlStateNormal];
    
    
    
    [self.view addSubview:logBtn];
    
}
- (void) loginclick
{
    // 回退键盘
    [self.view endEditing:YES];
    
    
    if (_accountField.text.length == 0 || _passWorldField.text.length == 0) {
      
        // 遮布显示时间
        [SVProgressHUD setMinimumDismissTimeInterval:0.1];
        
        //遮布
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
        
        //❌号+字
        [SVProgressHUD showErrorWithStatus:@"请填写全账户和密码"];
    }
    
    if ([_accountField.text isEqualToString:@"11"] && [_passWorldField.text isEqualToString:@"22"]) {
  
        // 遮布显示时间
        [SVProgressHUD setMinimumDismissTimeInterval:0.1];
        
        //遮布
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
        
        //❌号+字
        [SVProgressHUD showSuccessWithStatus:@"登陆成功"];
        
        
        [self.navigationController popToRootViewControllerAnimated:YES];
        
        
        
        if (self.logSuccessBlock) {
            
            self.logSuccessBlock();
            
        }
    
    }
    else
    {
        // 遮布显示时间
        [SVProgressHUD setMinimumDismissTimeInterval:0.1];
        
        //遮布
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeBlack];
        
        //❌号+字
        [SVProgressHUD showErrorWithStatus:@"账号或密码输入错误"];
    }
    
   
 


}
//点击空白处收回键盘
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    
    [_accountField resignFirstResponder];
    [_passWorldField resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
